package com.qian.fmall.detail.controller;

import com.qian.fmall.commons.ResultSet;
import com.qian.fmall.pojo.Product;
import com.qian.fmall.pojo.ProductSku;
import com.qian.fmall.product.service.ProductService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RequestMapping("detail")
@RestController
public class DetailController {
    @DubboReference
    private ProductService productService;
    @RequestMapping("list")
    public ResultSet getProductDetail(String productId)
    {
        HashMap<String, Object> productMap = new HashMap<>();
        Product product = productService.findProductByProductId(productId);
        List<ProductSku> productSkuList =productService.findProductSkuByProductId(productId);
        productMap.put("product",product);
        productMap.put("productSkuList",productSkuList);
        return ResultSet.ok("success",productMap);
    }

}
